/**
一个页面只许可一个TABLEPAGE控件
**/
function TablePageController(ControlName)
{
	this.objTablePage = eval("document.all."+ControlName);

//method
	this.SelectAMenu=TableController_SelectAMenu;						//选中指定的Menu,语法：obj.SelectAMenu(MenuIndex);
	//this.getMenuItem=TableController_getMenuItem;						
	this.setMenuItem=TableController_setMenuItem;						
	//this.getMenuTitle=TableController_getMenuURL;						
	//this.findtMenuTitle=TableController_getMenuURL;					
	//this.getMenuURL=TableController_getMenuURL;						
	//this.findMenuURL=TableController_findMenuURL;						//查找指定的Menu所对应的URL,只有在MenuContentType为file时候有效,语法：obj.findMenuURL(MenuIndex);
	this.init = TableController_Init;									//初始化一个TABPAGE控件
	this.initItem = TableController_InitAMenu;							//初始化一个Menu

//Read Only
	this.CurrentMenuIndex=-1;											//当前选择的TAB PAGE页的索引
	this.TotalMenuCount = 0;											//TAB页的menu数量
}

function TableController_InitAMenu(MenuIndex,MenuTitle)
{
	var menuItem = eval("document.all._SpanMenu" + MenuIndex);
	if(menuItem != null){
		menuItem.innerHTML = MenuTitle;
	}
}

function TableController_setMenuItem(MenuIndex,tabPageName)
{
	var menuItem = eval("document.all._ItemsContent" + MenuIndex);
	var source = eval("document.all." + tabPageName);
	if(menuItem != null){
		menuItem.innerHTML = source.outerHTML;
		source.parentElement.removeChild(source);
	}
	
}

function TableController_SelectAMenu(MenuIndex)
{
	for(i=0;i<this.TotalMenuCount;i++){
		if(i==MenuIndex){
			var menuBody = eval("document.all.mainTable.tBodies[" + i+"]");
			var menuItem = eval("document.all._ItemsContent" + i);
			var colItem = eval("document.all._TDItem" + i);
			menuBody.style.display="block";
			menuItem.firstChild.style.display="block";
			colItem.style.backgroundColor="cad6df";
		}else{
			var menuBody = eval("document.all.mainTable.tBodies[" + i+"]");
			var menuItem = eval("document.all._ItemsContent" + i);
			var colItem = eval("document.all._TDItem" + i);
			menuBody.style.display="none";
			menuItem.firstChild.style.display="none";
			colItem.style.backgroundColor="white";
		}
	}
}

function TableController_Init(TotalNum)
{
	var content = "<TABLE cellSpacing=0 cellPadding=0 width=\"100%\" bgColor=EEF0F2>\n";
	content += "	<TBODY>\n";
	content += "		<TR height=20 id==\"_MenuItems\">\n";
	for(i=0;i<TotalNum;i++){
		content += "		<TD vAlign=bottom width=80 id=\"_TdMenu"+i+"\">";
		content += "			<TABLE cellSpacing=0 cellPadding=0 width=\"100%\" bgColor=cad6df>\n"; 
        content += "	            <TBODY>\n";
		content += "					<TR>\n";
		content += "						<TD width=1 height=1></TD>\n";
		content += "						<TD width=1 height=1></TD>\n";
		content += "						<TD bgColor=white></TD>\n";
		content += "						<TD></TD>\n";
		content += "						<TD></TD></TR>\n";
		content += "					<TR>\n";
		content += "						<TD width=1 height=1></TD>\n";
		content += "						<TD width=1 bgColor=white height=1></TD>\n";
		content += "						<TD></TD>\n";
		content += "						<TD bgColor=black></TD>\n";
		content += "						<TD></TD></TR>\n";
		content += "					<TR>\n";
		content += "						<TD width=1 bgColor=white></TD>\n";
		content += "						<TD width=1 height=1></TD>\n";
		content += "						<TD id=btn2 style=\"PADDING-LEFT: 5px\" height=20>\n";
		content += "							<SPAN class=span id=_SpanMenu"+i+" style=\"WIDTH: 100%; CURSOR: hand\" onclick=\"TheTablePageControl.SelectAMenu("+i+")\"></SPAN></TD>\n";
        content += "			            <TD width=1 bgColor=gray></TD>\n";
        content += "			            <TD width=1 bgColor=black></TD></TR>\n";
		content += "			        <TR>\n";
		content += "			            <TD bgColor=white></TD>\n";
        content += "			            <TD id=\"_TDItem"+i+"\" bgColor=white colSpan=4 height=1></TD>\n";
		content += "			        </TR>\n";
		content += "			     </TBODY>\n";
		content += "			  </TABLE>\n";
		content += "		</TD>";
	}
    content += "            <TD style=\"BORDER-BOTTOM: #ffffff 1px solid\">&nbsp;</TD>";
	content += "		</TR>";
	//content += "		<TR height=20 id==\"_ItemsContent\">";
	//content += "		</TR>";
	content += "	</TBODY>";
	content += "</TABLE>";
	content += "<DIV style=\"BORDER-RIGHT: 2px outset; PADDING-RIGHT: 4px; PADDING-LEFT: 4px; PADDING-BOTTOM: 4px; BORDER-LEFT: white 1px solid; WIDTH: 100%; PADDING-TOP: 4px; BORDER-BOTTOM: 2px outset; HEIGHT: 94%; BACKGROUND-COLOR: cad6df\">";
	content += "<TABLE id=mainTable height=\"100%\" cellSpacing=0 cellPadding=0 width=\"100%\" border=0>";
	for(i=0;i<TotalNum;i++){
		content += "	<TBODY style=\"DISPLAY: none\">";
		content += "	    <TR>";
		content += "			<TD vAlign=top id=\"_ItemsContent"+i+"\">";
		content += "			</TD>";
		content += "		</TR>";
		content += "	</TBODY>";
	}
	content += "</TABLE>";
	content += "</DIV>";
	this.objTablePage.innerHTML = content;
	this.TotalMenuCount = TotalNum;
}
